<style lang="less">
  @import "permissionShow";
</style>

<template>
  <div class="permission">
    <div class="permission-card">
      <authority-form @authorityList="getResult"></authority-form>
    </div>
    <div class="permission-table">
      <Table border stripe ref="selection" :columns="columns" :data="data"></Table>
    </div>
  </div>
</template>

<script>
  import AuthorityForm from '../../../components/authority-form/authority-form'
  import {url} from '../../../../config/url'
    export default {
        name: "permissionShow",
      components:{
        AuthorityForm,
      },
      data(){
          return{
            columns: [
              {
                title: 'ID',
                key: 'id',
                width:90
              },
              {
                title: '权限名',
                key: 'name'
              },
              {
                title:'权限描述',
                key:'description'
              },
              {
                title:'代码',
                key:'code',
              },
              {
                title: '操作',
                key: 'handle',
                width:140,
                render: (h, params) => {
                  return h('div', [
                    //删除权限
                    h('Button', {
                      props: {
                        icon:'ios-trash'
                      },
                      style: {
                        marginRight: '5px'
                      },
                      on: {
                        click: () => {
                          this.remove(params.index)
                        }
                      }
                    }),
                  ]);
                }
              }
            ],
            data: [
            ]
          }
      },
      methods:{
        //获取查询权限的结果
        getResult(data){
          this.data=data
        },
        //删除权限
        remove (index) {
          let id=JSON.stringify([this.data[index].id]);
          this.$axios.delete(url+'/authority',{
            params:{
              'data':id
            }
          }).then(res=>{
            if(res.data.error_code==0){
              this.data.splice(index, 1);
              alert("删除角色成功")
            }
            else{
              alert("删除角色失败")
            }
          });
        }
      }
    }
</script>

<style scoped>

</style>
